package com.kmxd.ams.core.satoken;

import com.kmxd.ams.core.common.enums.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 枚举类转换配置
 *
 * @author admin
 */
@Slf4j
@Configuration
public class EnumConvertConfig implements WebMvcConfigurer {
  @Override
  public void addFormatters(FormatterRegistry registry) {
    WebMvcConfigurer.super.addFormatters(registry);
    registry.addConverter(
        new Converter<Integer, UseOrderOperateEnum>() {
          @Override
          public UseOrderOperateEnum convert(Integer source) {
            return UseOrderOperateEnum.getValue(source);
          }
        });
    registry.addConverter(
        new Converter<Integer, VolOrBoxTypeEnum>() {
          @Override
          public VolOrBoxTypeEnum convert(Integer source) {
            return VolOrBoxTypeEnum.getValue(source);
          }
        });

    registry.addConverter(
        new Converter<Integer, CreateEsIndexEnum>() {
          @Override
          public CreateEsIndexEnum convert(Integer source) {
            return CreateEsIndexEnum.getValue(source);
          }
        });

    registry.addConverter(
        new Converter<Integer, QuickSearchEnum>() {
          @Override
          public QuickSearchEnum convert(Integer source) {
            return QuickSearchEnum.getValue(source);
          }
        });
    registry.addConverter(
        new Converter<String, FieldOrderTypeEnum>() {
          @Override
          public FieldOrderTypeEnum convert(String source) {
            return FieldOrderTypeEnum.getValue(source);
          }
        });
    registry.addConverter(
        new Converter<Integer, UseTypeEnum>() {
          @Override
          public UseTypeEnum convert(Integer source) {
            return UseTypeEnum.getValue(source);
          }
        });

    registry.addConverter(
        new Converter<Integer, UsePushTypeEnum>() {
          @Override
          public UsePushTypeEnum convert(Integer source) {
            return UsePushTypeEnum.getValue(source);
          }
        });

    registry.addConverter(
        new Converter<String, OperatorEnum>() {
          @Override
          public OperatorEnum convert(String source) {
            return OperatorEnum.getValue(source);
          }
        });

    registry.addConverter(
        new Converter<Integer, UsePushOperateEnum>() {
          @Override
          public UsePushOperateEnum convert(Integer source) {
            return UsePushOperateEnum.getValue(source);
          }
        });
  }
}
